package org.subside.MQ.rabbitmq.TopicModel;

import com.rabbitmq.client.*;
import org.subside.MQ.rabbitmq.config.ConnectionUtil;

import java.io.IOException;


public class ConsumerGood {
    //声明交换机
    private static final String EXCHANGE_NAME = "exchange_topic";
    //*可以代表一个单词    #代表0个或多个单词
    private static final String ROUTINGKEY = "#.good.#";
    public static void main(String[] args) throws Exception {
        Connection connection =  ConnectionUtil.getConnection();        Channel channel = null;
        try {
            channel = connection.createChannel();
            channel.exchangeDeclare(EXCHANGE_NAME, "topic");
            channel.queueDeclare("goodQueue", false, false, true, null);
            //绑定队列
            channel.queueBind("goodQueue", EXCHANGE_NAME, ROUTINGKEY);
            DeliverCallback callback = (String consumerTag, Delivery message)->{
                String msg = new String(message.getBody(), "UTF-8");
                System.out.println(msg);
            };
            System.out.println("#.good.# 正在监听。。。。");
            channel.basicConsume("goodQueue", true, callback, consumerTag -> {});
        } catch (IOException e) {
            e.printStackTrace();
        }
 
    }
}